/**
 * 
 */
package de.cbf.cam.dsa.tavern.carte.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.ICellEditorListener;
import org.eclipse.jface.viewers.ICellEditorValidator;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;

import de.cbf.cam.dsa.tavern.carte.exceptions.WrongTypeProvidedException;
import de.cbf.cam.dsa.tavern.carte.model.entities.Ingredient;
import de.cbf.cam.dsa.tavern.carte.model.entities.MealType;
import de.cbf.cam.dsa.tavern.carte.model.entities.helper.MinMax;
import de.cbf.cam.dsa.tavern.carte.model.entities.helper.StringMinMax;
import de.cbf.cam.dsa.tavern.carte.model.entities.interfaces.IEditableEntity;
import de.cbf.cam.dsa.tavern.carte.ui.listeners.EnterPositiveDoubleForEvent;

/**
 * @author Stefan Alter
 *
 */
public class CompositeEditMealTypeData extends Composite {

	private Composite					compositeValues 			= null;
	private Composite					compositeAddendumCategories = null;
	private CompositeIngredients		compositeIngredients 		= null;	
	//
	private Label staticName			= null;
	private Label staticPrice			= null;
	private Label staticAddendums		= null;	
	private Text textName				= null;	
	private Text textPrice				= null;
	private Table tableConfig 			= null;
	private TableViewer tableViewer		= null;
	//	
	private Button buttonToAddendums	= null;
	private Button buttonFromAddendums	= null;
	
	/**
	 * @param parent
	 * @param style
	 */
	public CompositeEditMealTypeData(Composite parent, int style) {
		super(parent, style);
		initialize();		
	}

	/**
	 * This method initializes this
	 * 
	 */
	private void initialize() {
        GridLayout layout = new GridLayout();
	        layout.numColumns			= 2;	        
	        layout.horizontalSpacing	= 2;
	        layout.verticalSpacing		= 3;
	        layout.marginWidth			= 0;
	        layout.marginHeight 		= 0;
	        layout.marginTop			= 2;
	    //
        this.setLayout(layout);        
        //
        createCompositeValues();        
        createCompositeIngredients();
        createCompositeAddendumCategories();      
		//
        registerListeners();
        registerAdvancementListeners();
        //
        init();
	}
	private void registerListeners() {
		buttonToAddendums.addSelectionListener(addIngredient);
		buttonFromAddendums.addSelectionListener(removeIngredient);		
		//
		textName.addModifyListener(nameModify);		
		EnterPositiveDoubleForEvent.addToText(textPrice, priceModifyListeners);
		//
		tableConfig.addSelectionListener(configurationElementSelection);
		tableConfig.addKeyListener(tableKeys);
	}

	private void registerAdvancementListeners(){
		compositeIngredients.registerSelectionListener(ingredientSelection);
	}
	
	private void init() {		
		buttonFromAddendums.setEnabled(false);
		buttonToAddendums.setEnabled(false);		
	}

	/**
	 * This method initializes compositeValues	
	 */
	private void createCompositeValues() {
		GridLayout layoutCompositeValues = new GridLayout();
			layoutCompositeValues.numColumns		= 2;		
			layoutCompositeValues.marginWidth		= 0;
			layoutCompositeValues.marginHeight		= 0;
			layoutCompositeValues.horizontalSpacing	= 5;
			layoutCompositeValues.verticalSpacing	= 2;
		GridData gDCompositeValues = new GridData();
			gDCompositeValues.horizontalAlignment		= GridData.FILL;
			gDCompositeValues.verticalAlignment			= GridData.CENTER;
			gDCompositeValues.grabExcessHorizontalSpace	= false;
			gDCompositeValues.grabExcessVerticalSpace	= false;			
		GridData gDTextName = new GridData();
			gDTextName.horizontalAlignment			= GridData.FILL;
			gDTextName.verticalAlignment			= GridData.CENTER;
			gDTextName.grabExcessHorizontalSpace	= true;
		GridData gDTextPrice = new GridData();
			gDTextPrice.horizontalAlignment			= GridData.FILL;
			gDTextPrice.verticalAlignment			= GridData.CENTER;
			gDTextPrice.grabExcessHorizontalSpace	= true;		
		//
		compositeValues = new Composite(this, SWT.NONE);
		compositeValues.setLayout(layoutCompositeValues);
		compositeValues.setLayoutData(gDCompositeValues);	
		//
		staticName = new Label(compositeValues, SWT.NONE);
		staticName.setText("Name:");
		//
		textName = new Text(compositeValues, SWT.BORDER);
		textName.setLayoutData(gDTextName);
		//
		staticPrice = new Label(compositeValues, SWT.NONE);
		staticPrice.setText("Preis:");
		//
		textPrice = new Text(compositeValues, SWT.BORDER | SWT.RIGHT);
		textPrice.setLayoutData(gDTextPrice);
	}

	/**
	 * This method initializes compositeAddendumCategories	
	 *
	 */
	private void createCompositeAddendumCategories() {
		GridLayout layoutCompositeAddendumCategories = new GridLayout();
			layoutCompositeAddendumCategories.numColumns			= 2;			
			layoutCompositeAddendumCategories.marginWidth			= 0;
			layoutCompositeAddendumCategories.marginHeight			= 0;
			layoutCompositeAddendumCategories.horizontalSpacing		= 0;
			layoutCompositeAddendumCategories.verticalSpacing		= 0;
		GridData gDCompositeAddendumCategories = new GridData();			
			gDCompositeAddendumCategories.horizontalAlignment		= GridData.FILL;
			gDCompositeAddendumCategories.verticalAlignment			= GridData.FILL;
			gDCompositeAddendumCategories.grabExcessHorizontalSpace	= false;
			gDCompositeAddendumCategories.grabExcessVerticalSpace	= true;
		GridData gDStaticAddendums = new GridData();
			gDStaticAddendums.horizontalSpan 						= 2;
		GridData gDBtnFromAddendums = new GridData();			
			gDBtnFromAddendums.verticalAlignment = GridData.BEGINNING;
			gDBtnFromAddendums.horizontalAlignment = GridData.FILL;
			gDBtnFromAddendums.grabExcessVerticalSpace				= true;
		GridData gDBtnToAddendums = new GridData();
			gDBtnToAddendums.verticalAlignment						= GridData.END;
			gDBtnToAddendums.horizontalAlignment					= GridData.CENTER;
			gDBtnToAddendums.grabExcessVerticalSpace				= true;		
		GridData gridDataTable = new GridData();
	        gridDataTable.horizontalAlignment						= GridData.FILL;
	        gridDataTable.verticalAlignment							= GridData.FILL; 	        	      
	        gridDataTable.grabExcessHorizontalSpace					= false;
	        gridDataTable.grabExcessVerticalSpace 					= true;
	        gridDataTable.horizontalSpan							= 1;
	        gridDataTable.verticalSpan								= 2;			
		//
		compositeAddendumCategories = new Composite(this, SWT.NONE);
		compositeAddendumCategories.setLayoutData(gDCompositeAddendumCategories);
		compositeAddendumCategories.setLayout(layoutCompositeAddendumCategories);
		
		staticAddendums = new Label(compositeAddendumCategories,SWT.NONE);
		staticAddendums.setText("Addendums:");
		staticAddendums.setLayoutData(gDStaticAddendums);
		
		tableConfig = new Table(compositeAddendumCategories, SWT.BORDER|SWT.FULL_SELECTION);
	        tableConfig.setLayoutData(gridDataTable);
	        tableConfig.setHeaderVisible(true);
	        tableConfig.setLinesVisible(true);   
	        tableViewer = new TableViewer(tableConfig);
	        tableViewer.setContentProvider(ArrayContentProvider.getInstance());   
	        defineTableColumns();       
		
		buttonToAddendums = new Button(compositeAddendumCategories, SWT.NONE);
		buttonToAddendums.setText("<<");
		buttonToAddendums.setLayoutData(gDBtnToAddendums);
		
		buttonFromAddendums = new Button(compositeAddendumCategories, SWT.NONE);
		buttonFromAddendums.setText("XX");
		buttonFromAddendums.setLayoutData(gDBtnFromAddendums);
	}

	/**
	 * This method initializes compositeIngredients	
	 *
	 */
	private void createCompositeIngredients() {		
		GridData gDCompositeEntitiesIngredients = new GridData();
			gDCompositeEntitiesIngredients.horizontalAlignment			= GridData.FILL;
			gDCompositeEntitiesIngredients.verticalAlignment			= GridData.FILL;
			gDCompositeEntitiesIngredients.grabExcessHorizontalSpace	= true;
			gDCompositeEntitiesIngredients.grabExcessVerticalSpace		= true;		
			gDCompositeEntitiesIngredients.verticalSpan					= 2;
		//
		compositeIngredients = new CompositeIngredients(this, SWT.NONE);
		
		compositeIngredients.setLayoutData(gDCompositeEntitiesIngredients);
	}
	private void defineTableColumns() {
		TableViewerColumn columnIngredient = new TableViewerColumn(tableViewer, SWT.NONE);
        columnIngredient.getColumn().setText("Zutat");
        columnIngredient.getColumn().setWidth(90);
        columnIngredient.setLabelProvider(new CellLabelProvider() {				
			@Override
			public void update(ViewerCell cell) {
				cell.setText(((StringMinMax) cell.getElement()).getText());					
			}
		});	        
        columnIngredient.setEditingSupport(new NoEditSupport(tableViewer));
        
        TableViewerColumn columnMin = new TableViewerColumn(tableViewer, SWT.NONE);
        columnMin.getColumn().setText("Min");
        columnMin.getColumn().setWidth(40);
        columnMin.setLabelProvider(new CellLabelProvider() {				
			@Override
			public void update(ViewerCell cell) {
				cell.setText(((StringMinMax) cell.getElement()).getMin().toString());					
			}
		});
        columnMin.setEditingSupport(new EditMin(tableViewer));
        
        TableViewerColumn columnMax = new TableViewerColumn(tableViewer, SWT.NONE);
        columnMax.getColumn().setText("Max");
        columnMax.getColumn().setWidth(40);   
        columnMax.setLabelProvider(new CellLabelProvider() {				
			@Override
			public void update(ViewerCell cell) {
				cell.setText(((StringMinMax) cell.getElement()).getMax().toString());					
			}
		});
        columnMax.setEditingSupport(new EditMax(tableViewer));
	}

	public void clearData() {
		textName.setText("");
		textPrice.setText("");
		tableConfig.removeAll();		
	}
	
	@Override
	public void setEnabled(boolean enabled) {
		textName.setEnabled(enabled);
		textPrice.setEnabled(enabled);
		tableConfig.setEnabled(enabled);		
		compositeIngredients.setEnabled(enabled);
		if( ! enabled){
			buttonToAddendums.setEnabled(enabled);
			buttonFromAddendums.setEnabled(enabled);
		}		
//		super.setEnabled(enabled);
	}	
	
//	Properties getter setter helper ======================================
	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.ui.interfaces.ICompositeEditEntity#setEntity(de.cbf.cam.dsa.tavern.carte.model.entities.interfaces.IEditableEntity)
	 */	
	public void setEntityData(IEditableEntity value)
			throws IllegalArgumentException {		
		if (value instanceof MealType) {
			MealType mealType = (MealType) value;
			setMealTypeName(mealType.getName());
			setPrice(mealType.getPrice());
			setConfiguration(mealType.getConfigProbabilityMap());
		}else{
			if(value == null)return;
			throw new WrongTypeProvidedException(MealType.class,value.getClass());	
		}
	}
	
	public void setIngredients(Iterator<Ingredient> iteratorIngredients) {
		compositeIngredients.setObjects(Ingredient.transformIngredientIterator(iteratorIngredients).iterator());		
	}
	
	public Ingredient getSelectedTreeIngredient(){
		return (Ingredient)compositeIngredients.getSelectedObject();
	}
	public void setTreeSelectedIngredient(Ingredient value){
		compositeIngredients.setSelectedIngredient(value);		
	}
	public void deSelectAllTreeIngredients(){
		compositeIngredients.deSelectAll();
	}
	
	private Double parseDouble(String valueString){
		Double result = -1D;
		try{
			result = Double.parseDouble(valueString);
		}catch(NumberFormatException exc){			
		}
		return result;
	}
	private Integer parseInt(String valueString){
		Integer result = -1;
		try{
			result = Integer.parseInt(valueString);
		}catch(NumberFormatException exc){			
		}
		return result;
	}
	private TableItem getSelectedItem(){
		if(tableConfig.getSelectionCount() > 0){
			return tableConfig.getSelection()[0];
		}	
		return null;
	}
	
	public String getMealTypeName() {
		return textName.getText();
	}
	public void setMealTypeName(String value) {
		if(textName.getText().equals(value)) return;
		Point selection = textName.getSelection();
		textName.setText(value);
		textName.setSelection(selection);
	}

	public Double getPrice() {
		Double result = -1D;		
		result = parseDouble(textPrice.getText());
		return result;
	}
	
	public void setPrice(Double value) {
		if(getPrice().equals(value)) return;
		Point selection = textPrice.getSelection();
		textPrice.setText(value.toString());
		textPrice.setSelection(selection);
	}
	
	public String getSelectedIngredientName(){
		TableItem item = getSelectedItem();
		if(item != null){
			return item.getText(0);
		}
		return null;
	}
	public Ingredient getSelectedIngredient(){
		return compositeIngredients.getSelectedObject();
	}
	public Integer getSelectedMin(){
		TableItem item = getSelectedItem();
		if(item != null){
			return parseInt(item.getText(1));
		}
		return null;
	}
	public Integer getSelectedMax(){
		TableItem item = getSelectedItem();
		if(item != null){
			return parseInt(item.getText(2));
		}
		return null;
	}
		
	public void setSelectedItem(String ingredientName){
		
	}
	public int getSelectedIndex(){
		return tableConfig.getSelectionIndex();
	}
	public void setSelectedItem(int index){
		tableConfig.select(index);
	}
	
	public HashMap<String, MinMax> getConfiguration(){
		HashMap<String, MinMax> result = new HashMap<String, MinMax>();
		for (int i = 0; i < tableConfig.getItemCount(); i++) {
			TableItem item = tableConfig.getItem(i);
			String ingredientName = item.getText(0);
			MinMax probability = new MinMax();
			probability.setMin(parseInt(item.getText(1)));
			probability.setMax(parseInt(item.getText(2)));		
			//
			result.put(ingredientName, probability);
		}
		return result;
	}
	
	public void setConfiguration(HashMap<String, MinMax> value){
		int index = tableConfig.getSelectionIndex();
		tableConfig.removeAll();
		//
		Collection<String> keys = value.keySet();
		//sort list alphabetically	
		String[] ingredients = new String[0];
		ingredients = keys.toArray(ingredients);
		Arrays.sort(ingredients);
		StringMinMax[] elements = new StringMinMax[ingredients.length];
		for (int i = 0; i < elements.length; i++) {
			StringMinMax element = new StringMinMax();
			MinMax prob = value.get(ingredients[i]);
			element.setText(ingredients[i]);
			element.setMin(prob.getMin());
			element.setMax(prob.getMax());			
			//
			elements[i] =  element;		
		}
		tableViewer.setInput(elements);
		tableConfig.setSelection(index);
		if(index > -1){			
			tableConfig.notifyListeners(SWT.Selection,new Event());
		}		
	}
	
//	button en-/disabling ================================================
	
	
	public void setButtonAddEnabled(boolean value){
		buttonToAddendums.setEnabled(value);
	}
	public void setButtonRemoveEnabled(boolean value){
		buttonFromAddendums.setEnabled(value);
	}
	
	
	
	private Collection<ActionListener> nameModifyListeners = new ArrayList<ActionListener>();
	public boolean registerNameModifyListener(ActionListener listener){
		return nameModifyListeners.add(listener);
	}
	public boolean deRegisterNameModifyListener(ActionListener listener){
		return nameModifyListeners.remove(listener);
	}
	private NameModifyAdvancer nameModify = new NameModifyAdvancer();  //  @jve:decl-index=0:
	private class NameModifyAdvancer implements ModifyListener{
		@Override
		public void modifyText(ModifyEvent e) {
			ActionEvent event = new ActionEvent(CompositeEditMealTypeData.this, ActionEvent.ACTION_PERFORMED, "NameModify");
			for (ActionListener listener : nameModifyListeners) {
				listener.actionPerformed(event);
			}			
		}			
	}
	private Collection<ActionListener> priceModifyListeners = new ArrayList<ActionListener>();
	public boolean registerPriceModifyListener(ActionListener listener){
		return priceModifyListeners.add(listener);
	}
	public boolean deRegisterPriceModifyListener(ActionListener listener){
		return priceModifyListeners.remove(listener);
	}
	//see register listeners for "missing" Price modify listener, it is
	//incorporated in EnterPositiveDoubleForEvent
	
	private Collection<ActionListener> ingredientSelectionListeners = new ArrayList<ActionListener>();
	public boolean registerIngredientSelectionListener(ActionListener listener){
		return ingredientSelectionListeners.add(listener);
	}
	public boolean deRegisterIngredientSelectionListener(ActionListener listener){
		return ingredientSelectionListeners.remove(listener);
	}
	private IngredientSelectionAdvancer ingredientSelection = new IngredientSelectionAdvancer();	
	private class IngredientSelectionAdvancer implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent e) {
			ActionEvent event = new ActionEvent(CompositeEditMealTypeData.this, ActionEvent.ACTION_PERFORMED, "IngredientSelection:"+e.getActionCommand());
			for (ActionListener listener : ingredientSelectionListeners) {
				listener.actionPerformed(event);
			}
		}		
	}
	
	private Collection<ActionListener> configurationSelectionListeners = new ArrayList<ActionListener>();  //  @jve:decl-index=0:
	public boolean registerConfigurationSelectionListener(ActionListener listener){
		return configurationSelectionListeners.add(listener);
	}
	public boolean deRegisterConfigurationSelectionListener(ActionListener listener){
		return configurationSelectionListeners.remove(listener);
	}
	private Collection<ActionListener> addIngredientListeners = new ArrayList<ActionListener>();  //  @jve:decl-index=0:
	public boolean registerAddIngredientListener(ActionListener listener){
		return addIngredientListeners.add(listener);
	}
	public boolean deRegisterAddIngredientListener(ActionListener listener){
		return addIngredientListeners.remove(listener);
	}
	private AddIngredientAdvancer addIngredient = new AddIngredientAdvancer();  //  @jve:decl-index=0:
	private class AddIngredientAdvancer extends SelectionAdapter{
		@Override
		public void widgetSelected(SelectionEvent e) {
			ActionEvent event = new ActionEvent(CompositeEditMealTypeData.this, ActionEvent.ACTION_PERFORMED, "AddIngredient");
			for (ActionListener listener : addIngredientListeners) {
				listener.actionPerformed(event);
			}
		}		
	}
	private Collection<ActionListener> removeIngredientListeners = new ArrayList<ActionListener>();  //  @jve:decl-index=0:
	public boolean registerRemoveIngredientListener(ActionListener listener){
		return removeIngredientListeners.add(listener);
	}
	public boolean deRegisterRemoveIngredientListener(ActionListener listener){
		return removeIngredientListeners.remove(listener);
	}
	private RemoveIngredientAdvancer removeIngredient = new RemoveIngredientAdvancer();  //  @jve:decl-index=0:
	private class RemoveIngredientAdvancer extends SelectionAdapter{
		@Override
		public void widgetSelected(SelectionEvent e) {
			signalRemoveIngredient();
		}		
	}
	private TableKeys tableKeys = new TableKeys();  //  @jve:decl-index=0:
	private class TableKeys extends KeyAdapter{
		@Override
		public void keyPressed(KeyEvent e) {
			if(e.keyCode == SWT.DEL){
				signalRemoveIngredient();
			}
		}		
	}
	private Collection<ActionListener> modifyConfigurationListeners = new ArrayList<ActionListener>();  //  @jve:decl-index=0:
	public boolean registerModifyConfigurationListener(ActionListener listener){
		return modifyConfigurationListeners.add(listener);
	}
	public boolean deRegisterModifyConfigurationListener(ActionListener listener){
		return modifyConfigurationListeners.remove(listener);
	}
	private void signalConfigurationModification(){
		ActionEvent event = new ActionEvent(CompositeEditMealTypeData.this, ActionEvent.ACTION_PERFORMED, "ModifyConfiguration");
		for (ActionListener listener : modifyConfigurationListeners) {
			listener.actionPerformed(event);
		}
	}
	private void signalRemoveIngredient(){
		ActionEvent event = new ActionEvent(CompositeEditMealTypeData.this, ActionEvent.ACTION_PERFORMED, "RemoveIngredient");
		for (ActionListener listener : removeIngredientListeners) {
			listener.actionPerformed(event);
		}
	}

	private Collection<ActionListener> configurationElementSelectionListeners = new ArrayList<ActionListener>();  //  @jve:decl-index=0:
	public boolean registerConfigurationElementSelectionListener(ActionListener listener){
		return configurationElementSelectionListeners.add(listener);
	}
	public boolean deRegisterConfigurationElementSelectionListener(ActionListener listener){
		return configurationElementSelectionListeners.remove(listener);
	}
	private ConfigurationElementSelectionAdvancer configurationElementSelection = new ConfigurationElementSelectionAdvancer();  //  @jve:decl-index=0:
	private class ConfigurationElementSelectionAdvancer extends SelectionAdapter{
		@Override
		public void widgetSelected(SelectionEvent e) {
			ActionEvent event = new ActionEvent(CompositeEditMealTypeData.this, ActionEvent.ACTION_PERFORMED, "ConfigurationElementSelection");
			for (ActionListener listener : configurationElementSelectionListeners) {
				listener.actionPerformed(event);
			}
		}		
	}
	
	
	private class NoEditSupport extends EditingSupport{
		public NoEditSupport(ColumnViewer viewer) {
			super(viewer);			
		}
		@Override
		protected boolean canEdit(Object element) {			
			return false;
		}
		@Override
		protected CellEditor getCellEditor(Object element) {
			return null;
		}
		@Override
		protected Object getValue(Object element) {		
			return null;
		}
		@Override
		protected void setValue(Object element, Object value) {			
		}		
	}
	private class EditIntegers extends NoEditSupport{
		public EditIntegers(ColumnViewer viewer) {
			super(viewer);
		}
		@Override
		protected boolean canEdit(Object element) {
			return true;
		}
		@Override
		protected CellEditor getCellEditor(Object element) {
			final TextCellEditor editor = new TextCellEditor(tableConfig, SWT.NONE);	
			editor.setValidator(new ICellEditorValidator() {				
				@Override
				public String isValid(Object value) {
					try{
						Integer.parseInt(value.toString());
//						System.out.println(value.toString()+"... is valid");
					}catch (NumberFormatException e) {
//						System.out.println(value.toString()+"... is NOT valid");
						return "Bitte nur Zahlenwerte eingeben"; 
						//text is never shown, better this way, because checks every modification						
					}
					return null;
				}
			});
			editor.addListener(new ICellEditorListener(){
				@Override
				public void applyEditorValue() {
					
				}

				@Override
				public void cancelEditor() {
				}

				@Override
				public void editorValueChanged(boolean oldValidState,
						boolean newValidState) {					
				}
				
			});
			return editor;
		}		
	}
	private class EditMin extends EditIntegers{
		public EditMin(ColumnViewer viewer) {
			super(viewer);
		}
		@Override
		protected Object getValue(Object element) {
			return ((StringMinMax)element).getMin().toString();
		}
		@Override
		protected void setValue(Object element, Object value) {
			if(value == null)return;
			((StringMinMax) element).setMin(Integer.parseInt(value.toString()));
		    tableViewer.refresh(element);
		    signalConfigurationModification();
		}		
	}
	private class EditMax extends EditIntegers{
		public EditMax(ColumnViewer viewer) {
			super(viewer);		
		}
		@Override
		protected Object getValue(Object element) {
			return ((StringMinMax)element).getMax().toString();
		}
		@Override
		protected void setValue(Object element, Object value) {
			if(value == null)return;
			((StringMinMax) element).setMax(Integer.parseInt(value.toString()));
		    tableViewer.refresh(element);
		    signalConfigurationModification();
		}
	}
	
	
	
}
